package com.atguigu.ssyx.acl.service.impl;

import com.atguigu.ssyx.acl.mapper.AdminMapper;
import com.atguigu.ssyx.acl.service.AdminService;
import com.atguigu.ssyx.model.acl.Admin;
import com.atguigu.ssyx.vo.acl.AdminQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @作者:胡树苑
 * @时间:2025/9/11 08:43
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
    @Override
    public IPage<Admin> selectAdminPage(Page<Admin> page, AdminQueryVo adminQueryVo) {
        //获取条件值
        String username = adminQueryVo.getUsername();
        String name = adminQueryVo.getName();
        //创建mp条件对象
        LambdaQueryWrapper<Admin> wrapper = new LambdaQueryWrapper<>();
        //判断条件值是否为空，不为空封装查询条件
        if(!StringUtils.isEmpty(username)){
            wrapper.eq(Admin::getUsername, username);
        }
        if(!StringUtils.isEmpty(name)){
            wrapper.like(Admin::getName, name);
        }
        //调用方法实现条件分页查询
        IPage<Admin> adminPage = baseMapper.selectPage(page, wrapper);
        //返回分页对象
        return adminPage;
    }
}
